<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ include file="include.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ include file="menu.jsp" %>


<style type="text/css">
    .title {
        text-align: center;
        font-family: sans-serif;
        font-size: larger;
        color: #6699cc;
        width: 1000px;
        margin: 0 auto;
    }

    .grid {
        width: 1000px;
        margin: 0 auto;

    }

    .grid table {
        width: 100%;
       // border-collapse: collapse;
        font-size: 12px;
        font-family: Verdana;

    }

    .table_head {
        font-size: medium;
        text-align: center;
        font-weight: bold;
        background-color: #6699cc;
    }

    tr {
        height: 25px;
    }

    .form {
        width: 1000px;
        margin: 0 auto;
        font-family: sans-serif;
        font-style: normal;

    }

    .form select {
        width: 300px;
        border: medium solid #FFFFFF;
        background-color: #e0e0e0;
    }

    .form input {
        width: 300px;
    }

    input.button {
        cursor: pointer;
        background-color: #FFCC00;
        font-weight: bold;
        width: 100px;

    }

    .form td {
        font-size: x-small;
        font-weight: bold;

    }

    .required {
        color: red;
    }

    .active {
        background-color: #E1FFA7;
    }

    .inactive {
        background-color: #FFDDDC;
    }

    .table_row_1 {
        background-color: #e0e0e0;
    }
</style>

<div class="title">Управление хостами</div>
<br>

<div class="grid">
    <table>
        <tr class="table_head">
            <td width="10%">Имя хоста</td>
            <td width="10%">IP адрес</td>
            <td width="20%">CPU</td>
            <td width="20%">RAM</td>
            <td width="20%">HDD</td>
            <td width="10%">Статус</td>
            <td width="5%"></td>
            <td width="5%"></td>
        </tr>
    </table>
    <c:set var="count" value="0" scope="page"/>
    <c:forEach items="${host}" var="h">
        <c:set var="count" value="${count + 1}" scope="page"/>
        <div class="host">
            <table>
                <tr <c:if test="${(count % 2) == 0}"><c:out value="class=table_row_1"/></c:if> >


                    <td width="10%"><b><c:out value="${h.hostName}"/></b>&nbsp;
                        <c:out value="${cpuPercent}"/>                     &nbsp;
                    </td>
                    <td width="10%"><c:out value="${h.ipAddress}"/></td>

                    <td width="20%"><c:out value="Total: ${h.cpu} Usage: ${h.cpuUsage} %"/></td>

                    <td width="20%"><c:out value="${h.ram}"/>&nbsp;<c:out value="Usage = ${h.ramUsage} %"/></td>

                    <td width="20%"><c:out value="${h.hdd}"/>&nbsp;<c:out value="Usage = ${h.hddUsage} %"/></td>

                    <c:set var="statusName" value="${h.status.statusName}"/>
                    <td width="10%" align="center"
                            <c:if test="${statusName eq 'active'}"><c:out value="class=active"/></c:if>
                            <c:if test="${statusName eq 'inactive'}"><c:out value="class=inactive"/></c:if>
                            >
                        <c:out value="${h.status.alias}"/></td>


                    <c:set var="editValue" value="/admin/createHost.htm"/>
                    <c:set var="deleteValue" value="/admin/deleteHost.htm"/>

                    <c:url var="editUrl" value="${editValue}">
                        <c:param name="action" value="edit"/>
                        <c:param name="hostId" value="${h.hostId}"/>
                    </c:url>
                    <c:url var="deleteUrl" value="${deleteValue}">
                        <c:param name="action" value="delete"/>
                        <c:param name="hostId" value="${h.hostId}"/>
                    </c:url>

                    <td align="center" width="5%">
                        <a href="${editUrl}"><img style="border:0px;" src="../images/edit.png" alt="Edit"></a>
                    </td>
                    <td align="center" width="5%">
                        <a href="${deleteUrl}"><img style="border:0px;" src="../images/delete_red.png" alt="Delete"></a>
                    </td>
                </tr>
            </table>
            <div class="host_info" style="display:none;">
                <span>Подробная информация</span>
                <table border="1">
                    <tr>
                        <td class="label">Имя ресурса</td>
                        <td><c:out value="${h.hostName}"/></td>
                    </tr>
                    <tr>
                        <td class="label">IP Адрес</td>
                        <td><c:out value="${h.ipAddress}"/></td>
                    </tr>
                    <tr>
                        <td class="label">CPU</td>
                        <td><c:out value="${h.cpu}"/>&nbsp;GHz</td>
                    </tr>
                    <tr>
                        <td class="label">RAM</td>
                        <td><c:out value="${h.ram}"/>&nbsp;GB</td>
                    </tr>
                    <tr>
                        <td class="label">HDD</td>
                        <td><c:out value="${h.hdd}"/>&nbsp;GB</td>
                    </tr>
                    <tr>
                        <td class="label">Status</td>
                        <td><c:out value="${h.status.alias}"/></td>
                    </tr>
                </table>
            </div>
        </div>
    </c:forEach>


</div>

<div class="messages">

    <c:if test="${requestScope.errorMessage ne null}">
        <c:out value="${requestScope.errorMessage}"/>
    </c:if>

</div>

<div class="form">
    <form:form commandName="newHost">
          <fieldset>
            <table>
                <tr>
                    <td>Имя хоста<span class="required">*</span></td>
                    <td><form:input path="hostName"/></td>
                    <td><form:errors path="hostName" cssStyle="color:red"/></td>
                </tr>

                <tr>
                    <td>IP адрес<span class="required">*</span></td>
                    <td><form:input path="ipAddress"/></td>
                    <td><form:errors path="ipAddress" cssStyle="color:red"/></td>
                </tr>

                <tr>
                    <td>CPU, GHz <span class="required">*</span></td>
                    <td><form:select path="cpu">
                        <c:forEach items="${cpuList}" var="cpu">
                            <form:option value="${cpu}" label="${cpu} GHz"/>
                        </c:forEach>
                    </form:select>
                    </td>
                    <td><form:errors path="cpu" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td>HDD, Gb <span class="required">*</span></td>
                    <td><form:select path="hdd">
                        <c:forEach items="${hddList}" var="hdd">
                            <form:option value="${hdd}" label="${hdd} Gb"/>
                        </c:forEach>
                    </form:select>

                    </td>
                    <td><form:errors path="hdd" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td>RAM, Gb <span class="required">*</span></td>
                    <td><form:select path="ram">
                        <c:forEach items="${ramList}" var="ram">
                            <form:option value="${ram}" label="${ram} Gb"/>
                        </c:forEach>
                    </form:select>
                    </td>
                    <td><form:errors path="ram" cssStyle="color:red"/></td>
                </tr>

                <tr>
                    <td>Description</td>
                    <td><form:textarea cols="35" rows="5" path="description"/></td>
                    <td><form:errors path="description" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td>Status <span class="required">*</span></td>
                    <td><form:select path="status">
                        <form:options items="${statuces}" itemValue="statusId" itemLabel="alias"/>
                    </form:select>

                    </td>
                    <td><form:errors path="status" cssStyle="color:red"/></td>
                </tr>

                <tr>
                    <td></td>
                    <td align="right"><input type="submit" value="submit" class="button" id="submit"></td>
                    <td></td>
                </tr>


            </table>
        </fieldset>
    </form:form>
</div>